Python printing

Table of Contents

1. Get started

Create a folder in which to store your work for this assignment.

  • If you are working on your own computer, it’s up to you where to put the folder. Your desktop is likely as good a place as any. Make a folder titled pythonlab1.
  • If you are working in the labs in Olin, make sure to first mount the COURSES folder, so that you won’t lose your code when you log out. Once you’ve done so, open up Finder, then navigate to your personal student work folder. You can then make a pythonlab1 folder within there.
  • Once you’ve done so, you should then open up your new folder in VS Code. To do so, start up VS Code, then drag your folder onto the VS Code window. This should open up the folder within VS Code. If you are asked, click that you trust the authors.

2. Warmup

Within VS Code, create a new file within the folder you’ve opened. To do this, find the name of the folder on the left side of the window, and click the first icon to the right of it that looks like a sheet of paper which a plus symbol on the bottom right. This should create a file, and prompt you to give it a filename. Call it hello.py. This should create the file, and open it up for editing within VS Code.

Then, in the pane that VS Code opened up for editing, enter the following code:

print("Hello, world")

Then open up a terminal window (from the menu bar, choose “Terminal, New Terminal”), and type

python hello.py

If you’ve got everything set up right, it should print out the text Hello, world to the terminal. If not, get help on getting this working, as this is critical before going forward.

3. Display 111

Following the instructions above, create another file named display111.py. Write Python code so that it prints the following output:

\\\\\\\\\\\\\\\\\\\\
|| CARLETON CS111 ||
////////////////////

4. Response

Create another file named response.py. Write Python code so that when you run it, it asks the user to type in a response, and then it prints it output based on it as shown below. For example, here are two different results from running the program.

What is the phrase? hello
-----
YOU SAID: hello
hello IS WHAT YOU SAID
I HEARD hello TRULY hello hello IS WHAT I HEARD
-----
What is the phrase? Carleton College
-----
YOU SAID: Carleton College
Carleton College IS WHAT YOU SAID
I HEARD Carleton College TRULY Carleton College Carleton College IS WHAT I HEARD
-----

5. Escape 1

Create a file named escape1.py. Write Python code so that it always prints the following output. Note that the second line is indented by one tab.

Which is better?
    A \t or a \n?
/\_/\
 . .

6. Escape 2

Create a file names escape2.py. Write Python code so that it always prints the following output.

x"-"-"-"-"x
x\       \x
x/       /x
x\       \x
x/       /x
x\       \x
x"-"-"-"-"x

7. Grading

To receive a grade of “Meets expectations” for this assignment, you need to successfully complete all of the tasks above, except for the two “escape” tasks. If you complete everything successfully including the “escape” tasks, that will earn a grade of “Exemplary.”

For each of these exercises, I have provided automated tests via the CodeCheck website to see if these are correct. Each of the links below takes you to a CodeCheck exercise, for which you can copy and paste your code from VSCode, and run it. CodeCheck will then tell you whether or not you’ve gotten it correct. You can then modify your code and try again if you like.

Note that unlike our in-class labs, we are not using CodeCheck for grading of your assignments. That’s because I want you to get practice with the usual submission and grading that we’ll be using for the bigger assignments this term. So make sure you follow the directions below regarding turning in your code.

Here are the CodeCheck links that you can use for testing your code:

8. Turn in your programs

Unlike the in-class CodeCheck labs, these are not being autograded or connected directly to your Moodle account. Instead, you should submit this code to Moodle by uploading a single zip file. Don’t upload your Python programs one-by-one; instead, upload a single zip file that contains all of them. Do this by zipping (compressing) the entire folder, not each individual file. Here are instructions on how to do this on a Mac, and on Windows.

Once your zip file has been created, upload it to this Moodle assignment.

9. How get help

Remember that you have many sources of help! See the “How to get help” section of our Moodle page, which is in the Course Blocks at the top of the page.


Some of the exercises in this assignment are variations or inspirations from the book “Building Java Programs: A Back to Basics Approach or from supplemental exercises created by the authors of that book.

Author: Dave Musicant